package se.webbzon.boltzmann.minigame.botany;

import java.awt.Image;
import java.awt.Rectangle;

import se.webbzon.boltzmann.minigame.sandbox.DefaultSandBoxItem;
import se.webbzon.boltzmann.minigame.sandbox.SandBox;
import se.webbzon.boltzmann.minigame.sandbox.SandBoxIcon;
import se.webbzon.boltzmann.minigame.sandbox.SandBoxObject;
import se.webbzon.boltzmann.resource.Resources;
import se.webbzon.oschi01.resourceset.ResourceSet;
import se.webbzon.oschi01.worldarea.WorldArea;
import se.webbzon.oschi01.worldcamera.WorldCameraPane;
import se.webbzon.oschi01.worldobject.WorldObject;

public class Earth extends DefaultSandBoxItem {
	
	// The 2-dimensional depth of the cell
	private static final int depth = 150;
	
	// The default width and the height of the earth image
	private static final int defaultWidth = 96, defaultHeight = 48;
	
	// The image set of the earth
	private final ResourceSet<Image> imageSet;
	
	// The dimension of the sand box
	private final Rectangle r;
	
	/*============================================================
	Constructors
	============================================================*/
	
	public Earth() {
		imageSet = Resources.getImageSet("biology_earth_2");
		setInstance(new Instance());
		setSize(defaultWidth,defaultHeight);
		r = new Rectangle();
	}
	
	/*============================================================
	Public Methods
	============================================================*/
	
	@Override public void setSize(double w, double h) {
		super.setSize(w, h);
	}
	
	/*============================================================
	Private Classes
	============================================================*/
	
	private final class Instance extends SandBoxObject {

		public Instance() {
			super(WorldObject.onPostDraw, depth);
		}

		@Override public void onAttach(SandBox box) {
			box.getBoundary(r);
		}

		@Override public void onDetach(SandBox box) {
		}

		@Override public SandBoxIcon createIcon() {
			return null;
		}

		@Override public void onPostDraw(WorldArea world, WorldCameraPane hud) {
			int w = (int) getWidth();
			int h = (int) getHeight();
			int y = (int) r.getHeight() - h;
			int dx = w;
			for (int x = 0; x < (int) r.getWidth(); x += dx) {
				hud.drawImage(imageSet.get(0), x, y, w, h);
			}
		}
		
	}

}
